package com.meshnetics.gb.event;

/**
 * Class representing event type.
 *
 * @author mmarkov
 */
public abstract class EventType {    
    /** Integer type of this EventType. */
    protected int type;

    /** Name of this EventType. */
    protected String name;

    /**
     * Constructs EventType from the given integer type and name.
     *
     * @param type integer type
     * @param name the name of EventType
     */
    public EventType(int type, String name) {
        this.type = type;
        this.name = name;
    }

    /**
     * Returns integer type of this EventType.
     *
     * @return integer type of this EventType
     */
    public int getType() {
        return type;
    }

    /**
     * Returns true if this EventType includes the given one and false otherwise.
     *
     * @param type EventType to compare
     * @return true if this EventType includes the given one and false otherwise
     */
    public abstract boolean matches(EventType type);

    /**
     * Returns true if this EventType is a composite type (i.e. combination of 2 or more types or ANY_TYPE)
     * and false otherwise.
     *
     * @return true if this EventType is a composite type (i.e. combination of 2 or more types or ANY_TYPE)
     *         and false otherwise.
     */
    public abstract boolean isComposite();

    /**
     * Returns a hash code of this EventType which is it's integer type.
     *
     * @return a hash code of this EventType which is it's integer type
     */
    public int hashCode() {
        return type;
    }

    /**
     * Compares the given object for the equality with this EventType.
     *
     * @param obj the Object to compare with
     * @return true if the given Object is a EventType with the same type as this one
     *         and false otherwise
     */
    public boolean equals(Object obj) {
        return ((obj instanceof EventType) && ((EventType) obj).type == type);
    }

    /**
     * Returns a string representation of this EventType.
     *
     * @return a string representation of this EventType
     */
    public String toString() {
        return name;
    }
}
